<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>用户登录</title>
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<link rel="stylesheet" href="static/plugins/bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="static/plugins/bower_components/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="static/plugins/bower_components/Ionicons/css/ionicons.min.css">
		<link rel="stylesheet" href="static/dist/css/AdminLTE.min.css">
		<link rel="stylesheet" href="static/plugins/iCheck/square/blue.css">
		<link rel="stylesheet" type="text/css" href="static/plugins/bootstrapvalidator/dist/css/bootstrapValidator.min.css" />

		<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

		<style type="text/css">
			.error1 {
				display: none;
				color: #DD4B39;
			}
			
			.help-block {
				color: #DD4B39;
			}
			#tishi{
				width: 100%;
				text-align: center;
				font-size:14px;
				color: #ff6700;
			}
		</style>
	</head>

	<body class="hold-transition login-page">
		<div class="login-box">
			<div class="login-logo">
			</div>
			<div class="login-box-body">
				<p class="login-box-msg">用户登录</p>
				<p id="tishi"></p>
				<form method="post" id="login" action="/login">
					<div class="form-group has-feedback">
						<input name="Email" type="email" class="form-control Email" placeholder="Email">
						<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
						<p class="error1">Email不能为空！</p>
					</div>
					<div class="form-group has-feedback">
						<input name="Password" type="password" class="form-control Password" placeholder="Password">
						<span class="glyphicon glyphicon-lock form-control-feedback"></span>
					</div>
					<div class="row">
						<div class="col-xs-8">
							<div class="checkbox icheck" style="margin-left: 20px;">
								<label>
              <input type="checkbox" name="checkbox" class="remember">记住我
            </label>
							</div>
						</div>
						<div class="col-xs-4">
							<input type="submit" name="" id="login" class="btn btn-primary btn-block btn-flat login" value="Sign In" />
						</div>
					</div>
				</form>
				<a href="#">忘记密码？</a><br>
				<a href="register.html" class="text-center">注册新用户</a>
			</div>
		</div>
		<script src="static/plugins/bower_components/jquery/dist/jquery.min.js"></script>
		<script src="static/plugins/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="static/plugins/iCheck/icheck.min.js"></script>
		<script src="static/plugins/bootstrapvalidator/dist/js/bootstrapValidator.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("#login").bootstrapValidator({
					fields: {
						Email: {
							validators: {
								notEmpty: {
									message: '邮箱不能为空'
								},
								emailAddress: {
									message: '请输入有效的邮箱地址'
								}
							}
						},
						Password: {
							validators: {
								notEmpty: {
									message: '密码不能为空'
								},
								identical: {
									field: 'confirmPassword',
									message: '两次密码不一致'
								},
								different: {
									field: 'username',
									message: '密码不能和用户名相同'
								}
							}
						}

					}
				}).on('success.form.bv', function(event, data) {
					event.preventDefault();
						var Email = $(".Email").val();
						var Password = $(".Password").val();
						var remember = $(".remember")[0].checked ? 1 : 0;
						if(Email != "" && Password != "") {
							$.ajax({
								type: "post",
								url: "/postlogin",
								data: {
									Email: Email,
									password: Password,
									remember: remember
								},
								success: function(data) {
									var response=$.parseJSON(data);
									if(response.code==1){
										$("#tishi").html("用户不存在或者密码错误");
									}else if(response.code==0){
										location.href = "/index";
									}
								}
							});
						}
				});
			});
		</script>
	</body>

</html>